package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * ClassName: SupplierController
 * Package: com.atguigu.jxc.controller
 *
 * @Description: 供应商管理
 * @Author: xvyy
 * @Create: 2025/2/21 - 10:37
 * @Version: v1.0
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 查询供应商列表
     *
     * @param page
     * @param rows
     * @param supplierName
     * @return Map<String, Object> 供应商列表
     */
    @PostMapping("/list")
    @RequiresPermissions(value = "供应商管理")
    public Map<String, Object> list(Integer page, Integer rows, String supplierName) {
        return supplierService.list(page, rows, supplierName);
    }

    /**
     * 保存供应商信息
     *
     * @param supplier
     * @return ServiceVO 保存供应商结果
     */
    @RequiresPermissions(value = "供应商管理")
    @PostMapping("/save")
    public ServiceVO save(Supplier supplier) {
        return supplierService.save(supplier);
    }

    /**
     * 删除供应商信息
     *
     * @param supplierIds
     * @return ServiceVO 删除供应商结果
     */
    @RequiresPermissions(value = "供应商管理")
    @PostMapping("/delete")
    public ServiceVO delete(@RequestBody String supplierIds) {
            return supplierService.delete(supplierIds);
    }


}
